﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FaultBackService.Models;

namespace FaultBackService.BLL
{
    class t_TurbDataGeneric
    {
        DAL.t_TurbDataGeneric dal = new DAL.t_TurbDataGeneric();

        /// <summary>
        /// 获取最新周期的十分钟平均数序列,赋值最新数据库时间
        /// </summary>
        /// <returns></returns>
        public IList<Models.t_TurbDataGenericViewModel> GetLastList(out DateTime currentTimeOfDB)
        {
            return dal.GetLastList(out currentTimeOfDB);
        }

        /// <summary>
        /// 获取最新的数据时间,若表中无数据，返回默认时间
        /// </summary>
        /// <returns></returns>
        internal DateTime GetLastTimeStamp()
        {
            var time= dal.GetLastTimeStamp();
            return new DateTime(time.Year, time.Month, time.Day, time.Hour, (time.Minute / 10) * 10 + 5, 0);
        }

        /// <summary>
        /// 指定数据时间，获取该时间所属周期的十分钟数据集合,按时间降序排列
        /// </summary>
        /// <param name="dataTime"></param>
        /// <returns></returns>
        internal IList<t_TurbDataGenericViewModel> GetViewList(DateTime dataTime)
        {
            var start = dataTime.AddMinutes(-5);
            var end = dataTime.AddMinutes(5);

            return GetViewList(start, end);
        }

        /// <summary>
        /// 获取指定时间区间内的数据集合,按时间降序排列
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        internal IList<t_TurbDataGenericViewModel> GetViewList(DateTime startTime, DateTime endTime)
        {
            return dal.GetViewList(startTime, endTime);
        }

        /// <summary>
        /// 获取指定时间区间内的数据集合,按时间升序排列
        /// </summary>
        /// <param name="dataTime"></param>
        /// <returns></returns>
        internal IList<t_TurbDataGeneric2> GetViewList2(DateTime startTime, DateTime endTime)
        {
            return dal.GetViewList2(startTime, endTime);
        }

        /// <summary>
        /// 获取指定日期的十分钟数据集合，按时间升序排列
        /// </summary>
        /// <param name="day"></param>
        /// <returns></returns>
        internal IList<t_TurbDataGeneric2> GetViewList2(DateTime day)
        {
            return GetViewList2(day, day.AddDays(1));
        }
    }
}
